package com.ruoyi.quartz.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quartz.domain.SysEmail;
import com.ruoyi.quartz.service.ISysEmailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 待删除邮箱记录Controller
 * 
 * @author ruoyi
 * @date 2020-12-15
 */
@Controller
@RequestMapping("/quartz/email")
public class SysEmailController extends BaseController
{
    private String prefix = "quartz/email";

    @Autowired
    private ISysEmailService sysEmailService;

    @RequiresPermissions("quartz:email:view")
    @GetMapping()
    public String email()
    {
        return prefix + "/email";
    }

    /**
     * 查询待删除邮箱记录列表
     */
    @RequiresPermissions("quartz:email:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysEmail sysEmail)
    {
        startPage();
        List<SysEmail> list = sysEmailService.selectSysEmailList(sysEmail);
        return getDataTable(list);
    }

    /**
     * 导出待删除邮箱记录列表
     */
    @RequiresPermissions("quartz:email:export")
    @Log(title = "待删除邮箱记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysEmail sysEmail)
    {
        List<SysEmail> list = sysEmailService.selectSysEmailList(sysEmail);
        ExcelUtil<SysEmail> util = new ExcelUtil<SysEmail>(SysEmail.class);
        return util.exportExcel(list, "email");
    }

    /**
     * 新增待删除邮箱记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存待删除邮箱记录
     */
    @RequiresPermissions("quartz:email:add")
    @Log(title = "待删除邮箱记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysEmail sysEmail)
    {
        return toAjax(sysEmailService.insertSysEmail(sysEmail));
    }

    /**
     * 修改待删除邮箱记录
     */
    @GetMapping("/edit/{emailId}")
    public String edit(@PathVariable("emailId") String emailId, ModelMap mmap)
    {
        SysEmail sysEmail = sysEmailService.selectSysEmailById(emailId);
        mmap.put("sysEmail", sysEmail);
        return prefix + "/edit";
    }

    /**
     * 修改保存待删除邮箱记录
     */
    @RequiresPermissions("quartz:email:edit")
    @Log(title = "待删除邮箱记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysEmail sysEmail)
    {
        return toAjax(sysEmailService.updateSysEmail(sysEmail));
    }

    /**
     * 删除待删除邮箱记录
     */
    @RequiresPermissions("quartz:email:remove")
    @Log(title = "待删除邮箱记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysEmailService.deleteSysEmailByIds(ids));
    }
}
